package org.oos.utils;

import java.util.ResourceBundle;
import java.util.logging.Filter;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;

public class OosLogger {

	private static class BlankLogger extends Logger {

		protected BlankLogger(String name, String resourceBundleName) {
			super(name, resourceBundleName);
		}

		@Override
		public synchronized void addHandler(Handler handler)
				throws SecurityException {
		}

		@Override
		public void config(String msg) {
		}

		@Override
		public void entering(String sourceClass, String sourceMethod,
				Object param1) {
		}

		@Override
		public void entering(String sourceClass, String sourceMethod,
				Object[] params) {
		}

		@Override
		public void entering(String sourceClass, String sourceMethod) {
		}

		@Override
		public void exiting(String sourceClass, String sourceMethod,
				Object result) {
		}

		@Override
		public void exiting(String sourceClass, String sourceMethod) {
		}

		@Override
		public void fine(String msg) {
		}

		@Override
		public void finer(String msg) {
		}

		@Override
		public void finest(String msg) {
		}

		@Override
		public Filter getFilter() {
			return null;
		}

		@Override
		public synchronized Handler[] getHandlers() {
			return null;
		}

		@Override
		public Level getLevel() {
			return null;
		}

		@Override
		public String getName() {
			return null;
		}

		@Override
		public Logger getParent() {
			return this;
		}

		@Override
		public ResourceBundle getResourceBundle() {
			return null;
		}

		@Override
		public String getResourceBundleName() {
			return "";
		}

		@Override
		public synchronized boolean getUseParentHandlers() {
			return false;
		}

		@Override
		public void info(String msg) {
		}

		@Override
		public boolean isLoggable(Level level) {
			return false;
		}

		@Override
		public void log(Level level, String msg, Object param1) {
		}

		@Override
		public void log(Level level, String msg, Object[] params) {
		}

		@Override
		public void log(Level level, String msg, Throwable thrown) {
		}

		@Override
		public void log(Level level, String msg) {
		}

		@Override
		public void log(LogRecord record) {
		}

		@Override
		public void logp(Level level, String sourceClass, String sourceMethod,
				String msg, Object param1) {
		}

		@Override
		public void logp(Level level, String sourceClass, String sourceMethod,
				String msg, Object[] params) {
		}

		@Override
		public void logp(Level level, String sourceClass, String sourceMethod,
				String msg, Throwable thrown) {
		}

		@Override
		public void logp(Level level, String sourceClass, String sourceMethod,
				String msg) {
		}

		@Override
		public void logrb(Level level, String sourceClass, String sourceMethod,
				String bundleName, String msg, Object param1) {
		}

		@Override
		public void logrb(Level level, String sourceClass, String sourceMethod,
				String bundleName, String msg, Object[] params) {
		}

		@Override
		public void logrb(Level level, String sourceClass, String sourceMethod,
				String bundleName, String msg, Throwable thrown) {
		}

		@Override
		public void logrb(Level level, String sourceClass, String sourceMethod,
				String bundleName, String msg) {
		}

		@Override
		public synchronized void removeHandler(Handler handler)
				throws SecurityException {
		}

		@Override
		public void setFilter(Filter newFilter) throws SecurityException {
		}

		@Override
		public void setLevel(Level newLevel) throws SecurityException {
		}

		@Override
		public void setParent(Logger parent) {
		}

		@Override
		public synchronized void setUseParentHandlers(boolean useParentHandlers) {
		}

		@Override
		public void severe(String msg) {
		}

		@Override
		public void throwing(String sourceClass, String sourceMethod,
				Throwable thrown) {
		}

		@Override
		public void warning(String msg) {
		}

	}
	
	private static Logger logger;
	
	private static boolean debug = false;
	
	public static void setDebugLogger(boolean debug) {
		OosLogger.debug = debug;
		logger = null;
	}
	
	/**
	 * 
	 * Get an instance of {@link Logger} that refers to OOS to enable filtering.
	 * 
	 * @return
	 */
	public static Logger getOOSLogger() {
		if(logger == null) {
			String name = "OOS";
			logger = Logger.getLogger(name);
			if(!debug) {
				logger = new BlankLogger(name, logger.getResourceBundleName());
			}
		}
		return logger;
	}

}
